#ifndef _Included_glguerin_io_imp_mac_macosx_TinFSRefItem
#define _Included_glguerin_io_imp_mac_macosx_TinFSRefItem
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif

/**
	 A TinFSRefItem is an FSRefItemX for MacOSXForker.
	<p>
	 This class assumes that another class (nominally MacOSXForker) has loaded
	 the necessary JNI library, and made the function-names in it available.
	<p>
	 Some static methods are synchronized.
	 This is done because only some of the underlying OS functions are not thread-safe,
	 or I don't know what their thread-safety is (typically, whether reentrant or not).
	 We use the class's own lock for this thread-safety, so it will block any thread that
	 tries to re-enter one of the thread-unsafe alias functions, or anything else where
	 I was unsure of the ultimate re-entrancy.
	 I assume this is enough.  That is, that I don't have to coordinate thread-safety
	 across processes, or with other libraries, or with other native code.
	 This assumption will be wrong if there's another JNI library that calls the same
	 functions, and doesn't use the same class-lock.  Not much I can do about that, though.
	<p>
	 <b>NOTES ON 64-BITNESS</b>
	<p>
	 As of March 2006, there is no 64-bit JVM on Mac OS X.  When there is one, read this.
	<p>
	 The JNI code may accept and return pointers that have been "type-punned" into Java types.
	 As of March 2006, the Java type used is int, which is 32-bits.
	 In order for this Java code to work with a 64-bit native library, the type-punned pointers
	 will have to be converted to a Java long, and corresponding changes made to the C code.
	 It's not just a matter of changing arg types and return types.
	 You'll also have to change some array-copies from Get/SetIntArrayRegion() to Get/SetLong...
	<p>
	 Type-punned pointers are currently used by this class in only two area:
	  FSIterators and AliasHandles.
	<p>
	 The FSIterator methods involved are:
	   begin(), next(), and end() at the higher level,
	   and openIterator(), bulkInfo(), and closeIterator() at the JNI level.
	<p>
	 The AliasHandle methods involved are:
	   newAlias(Pathname), writeAlias(), and createFinderAlias() at the higher level,
	  and newAlias(byte[],int[]), and maybe createAliasFile() at the JNI level.
	<p>
	 I don't think there are any other type-punned pointers used in this class or its C code.
	 However, I didn't exhaustively bench-check, and more to the point, there isn't a 64-bit
	 JVM I can target on Mac OS X, so this is all just speculative until we can run real code.
	 @author Gregory Guerin
	 
	 64 bitness modifications -- Shanmuga
*/

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    makeRef
 * Signature: ([BLjava/lang/String;[B)I
 */
 
 /**
	 Make the resultFSRef refer to the given file or directory,
	 calling FSMakeFSRefUnicode.
	 Return an OSErr value as the result.
	 None of the items may be null.
	<p>
	 If the targeted item doesn't exist, an error-code is returned.
	 Unlike with an FSSpec, an FSRef can't refer to a non-existent item.
	 The rest of the code in FSRefItem is responsible for handling non-existent targets,
	 so they can be encapsulated with behavior similar to a non-existent FSSpec.
	 will call .
*/
 
 
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_makeRef
  (JNIEnv *, jobject, jbyteArray, jstring, jbyteArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    getRefInfo
 * Signature: ([BI[B[C[B)I
 */
 
 /**
	 Get the FSCatalogInfo for theFSRef.
	 Return an OSErr value as the result.
	 The nameBuf and/or parentFSRef may be null.
*/

JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_getRefInfo
  (JNIEnv *, jobject, jbyteArray, jint, jbyteArray, jcharArray, jbyteArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    openRef
 * Signature: ([B[CB[S)I
 */
 
/**
	 Open the item's named fork, calling FSOpenFork.
	 Return an OSError value as the result.
*/
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_openRef
  (JNIEnv *, jobject, jbyteArray, jcharArray, jbyte, jshortArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    resolve
 * Signature: ([BZ[B[B)I
 */

 /**
	 This method is synchronized under the class-lock, to prevent re-entrant calls from
	 any other thread in the process from calling the thread-unsafe Alias Mgr functions.
*/ 
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_resolve
  (JNIEnv *, jclass, jbyteArray, jboolean, jbyteArray, jbyteArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    newAlias
 * Signature: ([B[J)I
 */
 
/**
	 This method is synchronized under the class-lock, to prevent re-entrant calls from
	 any other thread in the process from calling the thread-unsafe Alias Mgr functions.
	##  newAlias( byte[] fsRef, long[] aliasRef );
*/

JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_newAlias
  (JNIEnv *, jclass, jbyteArray, jlongArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    createAliasFile
 * Signature: (J[BLjava/lang/String;[B[I)I
 */
 
 /**
	 This method is synchronized under the class-lock, to prevent re-entrant calls from
	 any other thread in the process from calling the thread-unsafe Resource Mgr functions.
	##  createAliasFile( long aliasHandle, byte[] parentFSRef, String name, byte[] resultFSRef, int[] iconInfo );
*/


JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_createAliasFile
  (JNIEnv *, jclass, jlong, jbyteArray, jstring, jbyteArray, jintArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    createSymlink
 * Signature: (Ljava/lang/String;Ljava/lang/String;)I
 */
 
 /**
	 This method is synchronized under the class-lock, to block re-entrant calls from
	 any other thread in the process.
	##  createSymlink( String originalName, String symlinkName );
*/
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_createSymlink
  (JNIEnv *, jclass, jstring, jstring);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    changed
 * Signature: (IZ[B)I
 */
 
 /**
	 This method is synchronized under the class-lock, to prevent re-entrant calls from
	 any other thread in the process from calling the thread-safety-unknown FNNotify() functions.
	##  changed( int msgValue, boolean specifically, byte[] theFSRef );
*/
 
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_changed
  (JNIEnv *, jclass, jint, jboolean, jbyteArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    createRef
 * Signature: ([BLjava/lang/String;Z[B)I
 */
 
 /**
	 Create the file or directory referenced by the FSRef and other args,
	 calling FSCreateDirectoryUnicode() or FSCreateFileUnicode().
	 Return an OSErr value as the result.
	 None of the items may be null.
*/
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_createRef
  (JNIEnv *, jobject, jbyteArray, jstring, jboolean, jbyteArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    setRefInfo
 * Signature: ([BI[B)I
 */
 
 /**
	 Set the FSCatalogInfo for theFSRef, calling FSSetCatalogInfo.
	 Return an OSErr value as the result.
	 Returns OSError.
*/
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_setRefInfo
  (JNIEnv *, jobject, jbyteArray, jint, jbyteArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    deleteRef
 * Signature: ([B)I
 */
 
 /**
	 Delete the file or directory referenced by the FSRef,
	 without resolving any aliases.
	 Return an OSError value as the result.
	 Will call FSDeleteObject.
*/
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_deleteRef
  (JNIEnv *, jobject, jbyteArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    renameRef
 * Signature: ([BLjava/lang/String;[B)I
 */
 
 /**
	 Rename the file or directory referenced by the FSRef,
	 without resolving any aliases,
	 calling FSRenameUnicode.
	 Return an OSErr value as the result.
	 None of the items may be null.
*/

JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_renameRef
  (JNIEnv *, jobject, jbyteArray, jstring, jbyteArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    moveRef
 * Signature: ([B[B)I
 */
 
 /**
	 Move the file or directory referenced by the FSRef,
	 without resolving any aliases.
	 Return an OSError value as the result.
	 The destination must reference an existing directory.
*/
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_moveRef
  (JNIEnv *, jobject, jbyteArray, jbyteArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    openIterator
 * Signature: ([BI[J)I
 */

/**
	 Calls FSOpenIterator()
*/
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_openIterator
  (JNIEnv *, jclass, jbyteArray, jint, jlongArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    bulkInfo
 * Signature: (JI[B[C)I
 */
 
 /**
	 Calls FSGetCatalogInfoBulk() for info on a single item.
*/
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_bulkInfo
  (JNIEnv *, jclass, jlong, jint, jbyteArray, jcharArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    closeIterator
 * Signature: (J)I
 */
 
 /**
	 Calls FSCloseIterator()
*/
JNIEXPORT jint JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_closeIterator
  (JNIEnv *, jclass, jlong);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    findFolderX
 * Signature: (SIZ[S)S
 */
 
 /**
	 Calls FindFolder().
	 Returns OSError.
*/
JNIEXPORT jshort JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_findFolderX
  (JNIEnv *, jclass, jshort, jint, jboolean, jshortArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    volumeRefX
 * Signature: (SI[C[B)S
 */
 
 /**
	 will call FSGetVolumeInfo().
	 Returns OSError.
*/
JNIEXPORT jshort JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_volumeRefX
  (JNIEnv *, jclass, jshort, jint, jcharArray, jbyteArray);

/*
 * Class:     glguerin_io_imp_mac_macosx_TinFSRefItem
 * Method:    nativePrep
 * Signature: ()Z
 */
 
 /**
	 This idempotent method performs all the native-side once-only initialization.
	 It's synchronized on the class-lock so it can't be called re-entrantly from other threads.
	 That shouldn't happen, but one never knows.
	<p>
	 This method returns T for big-endian architecture, F for little-endian.
*/
JNIEXPORT jboolean JNICALL Java_glguerin_io_imp_mac_macosx_TinFSRefItem_nativePrep
  (JNIEnv *, jclass);

#ifdef __cplusplus
}
#endif
#endif
